﻿using System;
using Windows.UI.Notifications;
using Windows.Data.Xml.Dom;

namespace ShamsiCalendar
{
    public static class clsTileUpdater
    {

        public static void updateAppTile()
        {
            //Find the current shamsi date
            clsDateConverter.ShamsiDate CurrentShamsiDate = clsDateConverter.ToShamsi(DateTime.Now);
            string txtDaystr = clsDateConverter.ConvertDayToStr(DateTime.Now);
            string txtDayNo = CurrentShamsiDate.Day.ToString();
            string txtMount = clsDateConverter.ConvertMountToStr(CurrentShamsiDate.Mount);
            string txtYear = CurrentShamsiDate.Year.ToString();

            //update square tile
            XmlDocument TileSquare = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquareBlock);
            XmlNodeList xmlSquareEL1 = TileSquare.GetElementsByTagName("text");
            xmlSquareEL1[0].AppendChild(TileSquare.CreateTextNode(txtDayNo));
            xmlSquareEL1[1].AppendChild(TileSquare.CreateTextNode(txtMount));

            TileNotification mySquareTileNotification = new TileNotification(TileSquare);
            TileUpdateManager.CreateTileUpdaterForApplication().Update(mySquareTileNotification);

            //update wide tile
            XmlDocument TileWide = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWideBlockAndText02);
            XmlNodeList xmlWideEL1 = TileWide.GetElementsByTagName("text");
            xmlWideEL1[0].AppendChild(TileWide.CreateTextNode(txtDaystr));
            xmlWideEL1[1].AppendChild(TileWide.CreateTextNode(txtDayNo));
            xmlWideEL1[2].AppendChild(TileWide.CreateTextNode(txtMount));

            TileNotification myWideTileNotification = new TileNotification(TileWide);
            TileUpdateManager.CreateTileUpdaterForApplication().Update(myWideTileNotification);

            /*//set the update schedule
            XmlDocument TileWide1 = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWideBlockAndText02);
            XmlNodeList xmlWide1EL1 = TileWide1.GetElementsByTagName("text");
            xmlWide1EL1[0].AppendChild(TileWide1.CreateTextNode("seshanbeg"));
            xmlWide1EL1[1].AppendChild(TileWide1.CreateTextNode("88"));
            xmlWide1EL1[2].AppendChild(TileWide1.CreateTextNode("tiriri"));

            DateTimeOffset ScheduleUpdate = new DateTimeOffset(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day + 1));
            //TileUpdateManager.CreateTileUpdaterForApplication().AddToSchedule(new ScheduledTileNotification(TileSquare1, ScheduleUpdate));
            TileUpdateManager.CreateTileUpdaterForApplication().AddToSchedule(new ScheduledTileNotification(TileWide1, ScheduleUpdate));
             */
        }

    }
}
